/*-----------------------------------------------------------------------------
-通用开发平台:进度显示控件
-作者：张金军
-所有人：张金军
-版权：版权所有，张金军，2005-2015，保留所有权利
-----------------------------------------------------------------------------*/
Yacon.widget.PercentBar = function(conText)
{
	this.barID     = "";
	this.width     = 200;
	this.height    = 22;
	this.top       = 10;
	this.left      = 10;
	this.barsum    = -1;
	this.persum    = -1;
	this.percent   = 0;
	this.perWidth  = 0;
	this.perIndex  = 0;
	
	this.caption   = "";
			
	conText = conText ||{};
	
	Yacon.apply(this,conText);
	
	this.create();
}
Yacon.widget.PercentBar.Extend(Object,{
	create:function()
	{

		this.element    = document.createElement("SPAN");
		this.element.setAttribute("id",this.barID);
		this.element.className = "percentBar";
		
		
		this.barProgress    = document.createElement("SPAN");
		this.barProgress.setAttribute("id",this.barID+"_progress");
		this.barProgress.className = "barProgress";
		
		this.element.appendChild(this.barProgress);		
		document.body.appendChild(this.element);
		
		this.setSize(this.width,this.height);
		this.setPos(this.top,this.left);
		
		this.freshStatus();
				
	},
	setSize:function(pwidth,pheight)
	{
		 this.width = Yacon.getInt(pwidth);
		 this.height = Yacon.getInt(pheight);
		 
		 this.element.style.width =  this.width;		 
		 this.element.style.height = this.height;
	},
	
	setPos:function(ptop,pleft)
	{
		 this.top 		= Yacon.getInt(ptop);
		 this.left 		= Yacon.getInt(pleft);
		 
		 this.element.style.top =  this.top;		 
		 this.element.style.left = this.left;
	},
	setCaption:function(pcaption)
	{
		this.caption   = pcaption;
	},
	setPercent:function(ppersum,pbarsum)
	{
		
		this.barsum    = Yacon.getInt(pbarsum);
		this.persum    = Yacon.getInt(ppersum);
		if (this.barsum > 0 && this.persum > 0)
		{
			this.percent = (this.persum*100)/this.barsum;
		}
		
		this.perWidth  = (this.percent*this.width)/100 ;
		this.perIndex  = Yacon.getInt(this.percent*256/100);
		
		this.setHint();
		this.setStatus();
	},

	setHint:function()
	{
		var hint = "";
		if (!Yacon.isDefined(this.caption) && !this.caption.isEqual(""))
		{
			hint = this.caption +" : ";
		}
		if (this.percent >=0)
			hint = hint + this.percent +"%";
		
		
		this.element.setAttribute("title",hint);	
	},
	setStatus:function()
	{
		this.barProgress.style.height = this.height-2;
		this.barProgress.style.width  = this.perWidth ;
		this.barProgress.innerText    = this.percent + "%";
	},
	
	freshStatus:function()
	{
		var par = this;
	
		function _prefesh()
		{
			
			/**外部调用函数*/
			if (Yacon.isfireuserEvent(par.barID+"_refresh"))
				Yacon.fireUserEvent(par.barID+"_refresh",[par]);
			
			
			if (par.barsum > par.persum)
				setTimeout(_prefesh, 10); 			
		}
		_prefesh();
	}
});

